package pl.mdziedzic.unittest;


import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Pattern;

public class JunitTestCaseRemoteControl extends SeleneseTestCase {
	@Before
	public void setUp() throws Exception {
		selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://code.google.com/");
		selenium.start();
	}

	@Test
	public void testJunitTestCaseRemoteControl() throws Exception {
		selenium.open("/p/selenium/");
		selenium.click("link=Downloads");
		selenium.waitForPageToLoad("30000");
		verifyTrue(selenium.isTextPresent("chromedriver downloads.txt"));
		assertTrue(selenium.isTextPresent("chromedriver downloads.txt"));
		selenium.type("id=searchq", "test");
		selenium.click("css=span.inIssueList > form > input[type=\"submit\"]");
		selenium.waitForPageToLoad("30000");
		assertTrue(selenium.isTextPresent("Your search did not generate any results."));
		selenium.click("link=Wiki");
		selenium.waitForPageToLoad("30000");
		assertTrue(selenium.isElementPresent("id=can"));
		assertTrue(selenium.isTextPresent("NextSteps"));
		assertEquals("IPhoneDriver", selenium.getText("link=IPhoneDriver"));
		selenium.click("link=Issues");
		selenium.waitForPageToLoad("30000");
		assertTrue(selenium.isElementPresent("link=New issue"));
		verifyTrue(selenium.isElementPresent("link=Grid"));
		selenium.click("link=Source");
		selenium.waitForPageToLoad("30000");
		verifyTrue(selenium.isTextPresent("http://selenium.googlecode.com/svn/trunk/ selenium-read-only"));
		selenium.type("name=q", "search test");
		selenium.click("name=projectsearch");
		selenium.waitForPageToLoad("30000");
		assertEquals("Results 1 - 10 of 550 ListGrid", selenium.getText("//div[@id='maincol']/table/tbody/tr/td[2]"));
	}

	@After
	public void tearDown() throws Exception {
		selenium.stop();
	}
}
